package tr.com.netgis;

import tr.com.netgis.db.NGDbHelper;
import tr.com.netgis.db.NGDbHelper.Table;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

/**
 * 
 * @author NetGis
 *
 */
public class NotPostedLocationListActivity extends NGListActivity {

	private Button btnTemizle;
	private Button btnGonderilmeyenKacTane;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notpostedlist);
		btnTemizle = (Button) findViewById(R.id.ng_notposted_btnListTemizle);
		btnGonderilmeyenKacTane = (Button) findViewById(R.id.ng_notposted_btnGonderilmeyenler);
		
		btnTemizle.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mHelper.deleteAllLocations();
				mCursor.requery();
				mAdapter.notifyDataSetChanged();
			}
		});
		final Context ctx = this;
		btnGonderilmeyenKacTane.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Toast toast = Toast.makeText(ctx, Long.toString( mHelper.howManyLocations()), 3000);
				toast.show();	
			}	
		});
	}
	
	@Override
    public void onResume() {
        super.onResume();
        String[] columns = NGDbHelper.getColumns(Table.LOCATIONS);
        mCursor = mDb.query(NGDbHelper.TABLE_NAME_LOCATIONS, columns, null, null, null, null, null, null);
        String[] headers = new String[] {NGDbHelper.COL_LAT, NGDbHelper.COL_LON};
        mAdapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item,
                mCursor, headers, new int[]{android.R.id.text1, android.R.id.text2});
        getListView().setAdapter(mAdapter);
    }
	
	 
}
